#include <iostream>
using namespace std;
#include<string>
#include<math.h>
class Student{
   private:
   string name;
   int age;
   public:
   Student(string name, int age);
   string  GetName(){
      return name;
   }
   int GetAge(){
      return age;
   }
};
Student::Student(string name, int age){
    this->name=name;
    this->age=age;
}



class Student1{
   public:
   string name;
   int age;
  
   Student1(string name, int age);
   string  GetName(){
      return name;
   }
   int GetAge(){
      return age;
   }
};
Student1::Student1(string name, int age){
    this->name=name;
    this->age=age;
}


void add(int x,int y,int *sum){
   *sum=x+y;
}
void sub(int x,int y,int *s){
   
   *s=x-y;
   
}


//tortoise move
void FastPlod(int **Tortoise){
   *Tortoise=*Tortoise+3;
}
void Slip(int **Tortoise){
   *Tortoise=*Tortoise-6;
}
void SlowPlod(int **Tortoise){
   *Tortoise=*Tortoise+1;
}
//end tortoise move

//rabit move
void Sleep(int **Rabit){
   *Rabit=*Rabit;
}
void BigHop(int **Rabit){
   *Rabit=*Rabit+9;
}
void BigSlip(int **Rabit){
   *Rabit=*Rabit-12;
}
void SmallHop(int **Rabit){
   *Rabit=*Rabit+1;
}
void SmallSlip(int **Rabit){
   *Rabit=*Rabit-2;
}
//end rabit move

int main() {
   //no.1
   int a[10]={0};
   for(int i=0;i<10;i++){
      a[i]=i+1;
   }
   for(int i=0;i<10;i++){
      cout<<i<<": "<<a[i]<<endl;
   }
cout<<"-----------------------"<<endl;
//no.2
   int b[7][7]={0};
   b[0][0]={};
   for(int i=1;i<7;i++){
      for(int j=1;j<7;j++){
         b[i][j]={i+j};
         cout<<b[i][j];
      
      }
      cout<<endl;
   }
cout<<"-----------------------"<<endl;
//no.3
   Student student[2]={Student ("Tom",19),Student ("Jerry",20)};
   for(int i=0;i<2;i++){
      cout<<student[i].GetName()<<": "<<student[i].GetAge()<<endl;
   }
cout<<"-----------------------"<<endl;
//no.4
int c=10;
int *ptr = &c;
cout<<" a "<<c<<endl;
cout<<" *ptr "<<*ptr<<endl;
cout<<" a address "<<&c<<endl;
cout<<" *ptr address "<<&(*ptr)<<endl;
cout<<"-----------------------"<<endl;
//no.5
int *p=a;
*p=*p+5;
cout<<" 5: "<<*p<<endl;

cout<<"-----------------------"<<endl;
//no.6
int x=1;
int y=2;
int sum,s;
void (*funcPointer)(int, int, int*);
funcPointer = add;
funcPointer(x,y,&sum);
cout<<sum<<endl;
funcPointer = sub;
funcPointer(y,x,&s);
cout<<s<<endl;


cout<<"-----------------------"<<endl;
//no.7
Student1 student1("wu",22);
Student1 *studentpointer;
studentpointer=&student1;
cout<<studentpointer->GetName()<<endl;
cout<<studentpointer->GetAge()<<endl;
cout<<"-----------------------"<<endl;
//no.8
string (Student1::*nameptr)()=Student1::GetName;
int (Student1::*ageptr)()=Student1::GetAge;
cout<<(student1.*nameptr)()<<endl;
cout<<(student1.*ageptr)()<<endl;
cout<<"-----------------------"<<endl;
//no.9
int arry1[3]={1,2,3};
int arry2[3]={4,5,6};
int arry3[3]={7,8,9};
int *p1[3]={arry1,arry2,arry3};
for(int i=0;i<3;i++){
   for(int j=0;j<3;j++){
   cout<<*p1[i]+j;
   }
   cout<<endl;
}

cout<<"-----------------------"<<endl;
//no.10

cout<<" bang!! "<<endl;
//build track
int track[70]={0};
for(int i=0;i<70;i++){
   track[i]=i+1;
}
int *Rabit=track;
int *Tortoise=track;


int rn=0;
srand(time(NULL));
rn=rand()%10;
while(1){
   if(1<=rn&&rn<=5){
      FastPlod(&Tortoise);
   }
   if(6<=rn&&rn<=7){
      Slip(&Tortoise);
   }
   if(8<=rn&&rn<=10){
      SlowPlod(&Tortoise);
   }
   if(1<=rn&&rn<=2){
      Sleep(&Rabit);
   }
   if(3<=rn&&rn<=4){
      BigHop(&Rabit);
   }
   if(rn==5){
      BigSlip(&Rabit);
   }
   if(6<=rn&&rn<=8){
      SmallHop(&Rabit);
   }
   if(9<=rn&&rn<=10){
      SmallSlip(&Rabit);
   }

int r=*Rabit;
int t=*Tortoise;

   if(r>=70){
      cout<<" rabit win "<<endl;
      break;
   }
   if(t>=70){
      cout<<" tortoise win "<<endl;
      break;
   }
   if(t==r||r==70){
      cout<<" it's tie "<<endl;
      break;
   }
}





   return 0;


}